<template>
  <!-- 通知通告查看页面 -->
  <div>
    <!-- 搜索 -->
    <TopFilter :list="topFilterInit" :cols="3" labelWidth="90" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <!-- table -->
    <FilterTable ref="table" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" :datakey="'records'" :isSelectColumn="false" :onColumnsChange="columns => this.columns = columns" columnsRef="todoTask_message_index_01">
    </FilterTable>

    <!-- 详情窗口 -->
    <Drawer :visible.sync="visibleDrawer" title="通知通告查看" :width="920" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <info-modal v-model="initData" @close="infoClose" />
    </Drawer>

  </div>
</template>

<script>
import { getList, getTodoList, addReadRecord ,getMessageCount} from '@/api/cms-api/todoTask/view/index';
import { dictionary } from '@/utils/dictMixin';
import infoModal from './info';
import { formatdateByDay } from '@/utils';
import { mapMutations } from 'vuex';


export default {
  mixins: [dictionary],
  components: {
    infoModal
  },
  data() {
    this.editHandle();
    return {
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      fetchApi: getList,
      fetchParams: {},
      visibleDrawer: false,
      initData: {}
    }
  },
  methods: {
    ...mapMutations('noticePanel', ['SET_NP_NUM']),
    topFilterInitFun() {
      return [
        { type: 'SELECT', label: '业务类型', fieldName: 'businessType', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1586') },
        { type: 'SELECT', label: '是否查看', fieldName: 'viewStatus', placeholder: '请输入', initialValue: '', itemList: this.createDictList('1004') },
        { type: 'RANGE_DATE', label: '消息时间', fieldName: 'createdAt', valueFormat: 'yyyy-MM-dd', placeholder: '请选择' }

      ]
    },
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row, 'show')}>
                  查看
                </el-button>
              </div>
            );
          }
        },
        {
          title: '业务类型',
          dataIndex: 'businessType',
          sorter: true,
          filterItems: this.createDictList('1586'),
          render: props => {
            return <span>{this.createDictText(props.row.businessType, '1586')}</span>;
          }
        },
        {
          title: '是否查看',
          dataIndex: 'viewStatus',
          sorter: true,
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.viewStatus, '1004')}</span>;
          }
        },
        {
          title: '提醒消息',
          dataIndex: 'taskMsg',
          sorter: true
        },
        { title: '提醒消息时间', dataIndex: 'createdAt', sorter: true, dateFormat: 'yyyy-MM-dd' }
        // { title: '提醒消息时间', dataIndex: 'publishDate',dateFormat:'yyyy-MM-dd HH:mm',sorter: true }
      ]
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
      this.editHandle();
      this.fetchParams.startDate = formatdateByDay(this.fetchParams.createdAt[0]);
      this.fetchParams.endDate = formatdateByDay(this.fetchParams.createdAt[1]);
      console.log('搜索框数据：', this.fetchParams);
    },
    //展开收起时触发
    collapseHandle() { },
    async editHandle(row, type) {
      var mes = await getMessageCount();

      console.log(mes.data);
      this.SET_NP_NUM({ name: 'num', value: mes.data.number});

      console.log("row:", row);
      this.initData = {
        type: type,   // add-edit-show
        notificationId: row.notificationId,
        id: 1001
      }; //行id
      if (row.viewStatus == 10041002) {
        var params = {
          todoTaskId: row.todoTaskId
        };

        var res = addReadRecord(params);
        //this.visibleDrawer = true;
      }

      this.$router.push({
        path: '/' + row.menu_url,
        query: {
          type: '123'
        }

      })
    },
    //关闭详情 rData 是页面关闭回调回来的数据
    infoClose(rData) {
      this.editHandle();
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
  }
};
</script>

<style lang="less" scoped>
</style>
